<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>散客资料</title>
<meta name="decorator" content="default" />
<style type="text/css">
fieldset {
	display: inline-block;
	width: 100%;
}

form {
	width: 95%;
	margin: auto;
}
</style>
<script type="text/javascript">
	$(document).ready(function() {
		$("#name").focus();
		$("#inputForm").validate({
			submitHandler : function(form) {
				jQuery.ajax({
					url : "isCustomerExist",
					type : "post",
					data : {
						id : function() {
							return "";
						},
						name : function() {
							return $("#name").val();
						},
						mobile : function() {
							return $("#mobile").val();
						}
					},
					success : function(data) {
						var jsonObjects=JSON.parse(data);
						var controlObj=jsonObjects[0];
						if (controlObj.result == "true") {
							loading('正在提交，请稍等...');
							$("table#contentTable tbody tr").remove();
							$("div#userlist").css("display","none");
							form.submit();
						} else {
						 
							showTip("该手机号已被注册！");
							var html="";
							for ( var index = 1; index < jsonObjects.length; index++) {
								html+="<tr><td>" +jsonObjects[index].name +"</td>";
								html+= "<td>" +jsonObjects[index].nickname +"</td>"; 
								html+= "<td>" +jsonObjects[index].storeName +"</td>"; 
								html+= "<td>" +jsonObjects[index].storeAddress +"</td>"; 
								html+= "</tr>"; 
							}
							$("div#userlist span").text($("#mobile").val());
							$("div#userlist").css("display","block");
							showTip("该手机号已被注册！");
							$("table#contentTable tbody tr").remove();
							$("table#contentTable").append(html);
							$("#contentTable").trigger("create");
						}
					},
					error : function(data) {
						showTip("操作失败");
					}
				});
			},
			focusInvalid : false,
			rules : {
				"mobile" : {
					isMobile : "#mobile"
				}
			},
			errorContainer : "#messageBox",
			errorPlacement : function(error, element) {
				$("#messageBox").text("输入有误，请先更正。");
				if (element.is(":checkbox") || element.is(":radio")) {
					error.appendTo(element.parent().parent());
				} else {
					error.insertAfter(element);
				}
			},
			messages : {
				weight : "格式有误！",
				email : "格式有误！",
				mobile : "手机号码格式有误！"
			}
		});
	});
</script>
</head>
<body>
	<h2 style="text-align: center;">快速注册成为会员</h2>
	<div class="icon-buttons">
		<a data-role="button" data-inline="true" data-icon="back"
			data-iconpos="notext" href="${ctx}/cash/consume/nonmember">返回</a>
	</div>
	<form:form id="inputForm" modelAttribute="customer"
		action="${ctx}/cash/consume/saveCustomer" method="post">
		<tags:message content="${message}" />
		<div data-role="fieldcontain">
			<label>客户姓名:</label>
			<form:input path="name" class="required" type="text" value="" />
		</div>
		<div data-role="fieldcontain">
			<label>手机:</label>
			<form:input path="mobile" class="required" type="tel" value=""
				maxlength="11" />
		</div>
		<div data-role="fieldcontain">
			<label>生日:</label> <input type="date" id="birthday"
				value="${fns:formatDate(customer.birthday,'yyyy-MM-dd')}"
				name="birthday" class="required" />
		</div>
		<div style="text-align: center;">
		<a data-role="button" href="${ctx}/cash/consume/unsaveCustomer"
			data-inline="true">暂不注册</a>
		<input id="btnSubmit" type="submit" value="确认注册会员" data-inline="true" />
        </div>
	</form:form>
	<div id="userlist" style="display: none;">
	    <h4 style="text-align: center;">该手机号码(<span></span>)已被如下客户所注册使用</h4>
	    <br/>
	  <table id="contentTable" data-role="table" class="ui-responsive table-stroke">
			<thead>
				<tr>
					<th>姓名</th>
					<th>备注名</th>
					<th>店面名称</th>
				    <th>店面地址</th>
				</tr>
			</thead>
			<tbody>
			</tbody>
		</table>
	</div>
</body>
</html>
